function coefs=fc(f, nstart, nend, Nt)
% Calculate Fourier Coefs
% input:
%        f: values of function L^2([0,1])
%        Nt+1: number of samples on time
%        nstart: start index of coefs;
%        nend: start index of coefs;
% output:
%        coefs: vector -- Frouier coefficients;
% Call: fft
% 
%----------------------------------------
% Principle: Apply trapzoid integral formula to Fourier transfrom.
% Application: Fourier coefficience
% Assertion: nstart - nend < Nt
% Example: 
% See also fft czt


if nargin<=3
    Nt=length(f)-1;
    if nargin<=1
        nstart=-floor(Nt /2);
        nend=Nt+nstart-1;
    end
end

t=linspace(0,1,Nt+1);

if iscolumn(f)
    t = t.';
end
coefs =(fft(f(1:end-1).*exp(-2i*pi*nstart*t(1:end-1))) + (f(end)-f(1))/2) /Nt;
coefs = coefs(1:nend-nstart+1);
end